package com.dingli.servlet.ajax;

import com.dingli.DAO.RoleLevelDAO;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(urlPatterns = "/getInfo")
public class RoleLevelServlet extends HttpServlet {
    private RoleLevelDAO roleLevelDAO = new RoleLevelDAO();

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String type = req.getParameter("type");
        List<Map<String, Object>> roleList = null;
        if(type.equals("role")){
            roleList = roleLevelDAO.getRole();
        } else if (type.equals("level")) {
            roleList = roleLevelDAO.getTicketLevel();
        }
        resp.getWriter().write(new ObjectMapper().writeValueAsString(roleList));
    }
}

